//
//  AppDelegate.swift
//  LspSwiftFinayTest
//
//  Created by lsp's mac pro on 2018/3/26.
//  Copyright © 2018年 lsp's mac pro. All rights reserved.
//

import UIKit
import UserNotifications
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        //获取用户授权然后显示app图片上面的bagenumber
        setupSVtime()
        //设置afn的网络加载指示器
        
       

        
        window=UIWindow()
        window?.backgroundColor=UIColor.white
        window?.rootViewController = LspNbTabBarViewController()
         loadDatainfo()
        window?.makeKeyAndVisible()
       
        return true
    }

 //模拟异步加载 模拟从服务器加载应用信息
    func loadDatainfo() {
        DispatchQueue.global().async {
            //1.url
            let  url = Bundle.main.url(forResource: "demo.json", withExtension: nil)
            //2.data
            let data=NSData(contentsOf:url!)
            //3.写入沙盒
            let docDir = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
            let jsonPath=(docDir as NSString).appendingPathComponent("demo.json")
             data?.write(toFile: jsonPath, atomically: true)
            print(docDir);
            
            
            
        }
    }

}
extension AppDelegate {
    
    private func setupSVtime(){
        //设置SVProgressHUD 的最小显示时间
        SVProgressHUD.setMinimumDismissTimeInterval(1)
        //设置afnnetworking 的旋转菊花
        AFNetworkActivityIndicatorManager.shared().isEnabled=true
        
        
        
        //如果ios10 以上用第一个方法  以下就用第二个方法
        if #available(iOS 10.0, *) {
          UNUserNotificationCenter.current().requestAuthorization( options: [.alert,.sound,.carPlay,.badge]) { (success, error) in
            }
        } else {
            /// 提示 声音和 数字显示
            let notifSettings=UIUserNotificationSettings(types: [.alert,.badge,.sound], categories: nil)
        UIApplication.shared.registerUserNotificationSettings(notifSettings)
        }
        
    }
}
